package com.xsz.service;

import com.xsz.entity.Product;
import com.xsz.mapper.ProductMapper;
import com.xsz.util.KeyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductService {
    @Resource
    ProductMapper productMapper;

    //新建
    public Product add(Product product) {
        product.setId(KeyUtil.getId());
        if(productMapper.insert(product)>0){
            return  product;
        }else{
            return null;
        }
    }

    //修改
    public int update(Product product) {
        return productMapper.updateByPrimaryKeySelective(product);
    }


    //删除
    public int delete(String id) {
        return productMapper.deleteByPrimaryKey(id);
    }

    //根据id查询
    public Product selectById(String id) {
        return productMapper.selectByPrimaryKey(id);
    }

    //查询所有
    public List<Product> getAll() {
        return productMapper.selectAll();
    }
}
